export const addToClipboard = function (text) {
  const textarea = document.createElement("textarea");
  textarea.value = text;
  // 添加样式使 textarea 不可见且不触发键盘
  textarea.style.position = "absolute";
  textarea.style.left = "-9999px";
  textarea.style.opacity = "0";
  textarea.style.userSelect = "none";
  textarea.readOnly = true; // 设置为只读，避免在移动设备上唤起键盘

  document.body.appendChild(textarea);
  textarea.select();
  document.execCommand("copy");
  document.body.removeChild(textarea);
};


// 生成随机密码
// FIXME: 优化入参方式，没空研究后期再改
export const generateRandomPassword = function (
  charset = "abcdefghijklmnopqrstuvwxyz0123456789",
  length = 6,
) {
  var password = "";
  for (var i = 0; i < length; i++) {
    var randomIndex = Math.floor(Math.random() * charset.length);
    password += charset.charAt(randomIndex);
  }
  return password;
};
